<template>
  <div>

    <el-row :gutter="20">
      <el-form :model="searchLsit" ref="searchLsit" size="normal">
        <el-col :span="8" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchLsit.code" clearable placeholder="账号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchLsit.name" clearable placeholder="名称"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <el-col :span="8" :offset="0">
        <div class="right">
          <el-button type="primary" size="default" @click="search" :loading="loading">查询</el-button>
        </div>
      </el-col>
    </el-row>

    <el-table :data="tebleData" border stripe v-loading="loading" :height="offsetHeight">
      <el-table-column type="index" label="序号" width="80" align="center">
      </el-table-column>
      <el-table-column prop="code" label="单位账号" width="" align="center">
      </el-table-column>
      <el-table-column prop="name" label="单位名称" width="" align="center">
      </el-table-column>
      <el-table-column prop="ensure_dept" label="保障部门" width="" align="center">
      </el-table-column>
      <el-table-column prop="remarks" label="财政处室" width="" align="center">
      </el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="edit(row)" :loading="saveLoading">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="机构设置" :visible.sync="show" width="30%" @close="cancel">
      <el-form :model="belongList" ref="belongList" label-width="100px" size="normal">
        <el-form-item label="单位名称">
          <el-input v-model="belongList.name"></el-input>
        </el-form-item>
        <el-form-item label="保障部门" v-show="belongList.ensure_dept">
          <el-select v-model="belongList.ensure_dept" value-key="ensure_dept" class="wid">
            <el-option v-for="item in ensureType" :key="item.no" :label="item.name" :value="item.no">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="财政处室" v-show="belongList.remarks">
          <el-select v-model="belongList.remarks" value-key="ensure_dept" class="wid">
            <el-option v-for="item in remarksType" :key="item.no" :label="item.name" :value="item.no">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button type="danger" @click="cancel">取消</el-button>
        <el-button type="primary" @click="onConfirm" :loading="loading">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'PartBelong',
  components: {

  },
  props: {

  },
  data () {
    return {
      offsetHeight: document.documentElement.clientHeight - 280,
      loading: false,
      saveLoading: false,
      searchLsit: {},
      tebleData: [],
      show: false,
      belongList: {},
      ensureType: [],
      remarksType: [],
    }
  },
  created () {

  },
  mounted () {
  },
  methods: {
    async init () {
      this.loading = true
      const res = await this.$http('sysBelongList', {
        ...this.searchLsit
      })
      this.tebleData = res

      const res1 = await this.$http('sysBelongType', {
        role_ids: 'ddd70dd9c42f476182b034c27813e3c9'
      })
      this.ensureType = res1

      const res2 = await this.$http('sysBelongType', {
        role_ids: '31598e09e255440e9e7e0191cf757a3c'
      })
      this.remarksType = res2
      this.loading = false
    },
    search () {
      this.init()
    },
    async edit (item) {
      this.saveLoading = true
      this.belongList = {
        ...item
      }
      this.show = true
      this.saveLoading = false
    },
    cancel () {
      this.show = false
    },
    async onConfirm () {
      const res = await this.$http('sysBelongUp', {
        source: '0',
        ...this.belongList
      })
      this.$tips.success(res.errmsg)
      this.show = false
      this.init()
    }
  },
  computed: {

  }
}
</script>
<style lang='scss' scoped>
</style>
